package com.gopay.webtest.controller.cloud;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.cloud.TransCloudSignHandler;
import com.gopay.webtest.util.DateUtils;
import com.gopay.webtest.vo.cloud.Cloud0603Vo;
import com.gopay.webtest.xml.XmlDao;

/**
 * 
 * ZhangZG
 * 2016年1月4日 
 * www.gopay.com.cn Inc.All rights reserved.
 */

@RequestMapping("/cloud")
@Controller
public class CloudAccoutController extends BaseController{
	
	
	@Resource(name = "xmlDao")
    private XmlDao xmlDao;
	
	@Resource(name="transCloudSignHandler")
	private TransCloudSignHandler transCloudSignHandler;
	
	
    @RequestMapping("/accoutApply")
    public ModelAndView chargeApply() {
        ModelAndView mv = new ModelAndView();

        
        try {
        	this.logger.error("^^^^^^^^^^^^^^^^^云平台账户锁定/解锁申请页面初始化成功^^^^^^^^^^^^^^^^^");
        	
        	 Map<String, String> map = xmlDao.readData4Map("cloud_apply", "apply");

             map.put("gopayServerTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             map.put("merOrderNum", System.currentTimeMillis()+"");
             mv = new ModelAndView("cloud.accout.apply");
             mv.addObject("config", map);
        	
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }
    
    
    @RequestMapping("/doAccoutSubmit")
    public ModelAndView doCharge(@ModelAttribute Cloud0603Vo req){
    	 ModelAndView mv = new ModelAndView();
         mv.setViewName("cloud.accout.doApply");

         try {
        	 this.logger.error("^^^^^^^^^^^^^^^^^云平台账户锁定/解锁申请页面签名成功^^^^^^^^^^^^^^^^^");
             // 签名
        	 transCloudSignHandler.sign(req.getTranCode()+"_"+req.getVersion(), "signType", "signValue", req, getRequest());


             mv.addObject("applyVo", req);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }
    
    
}
